package pzhu.web;

import java.io.IOException;

import org.apache.http.HttpEntity;
import org.apache.http.ParseException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.jsoup.Jsoup;
import org.jsoup.select.Elements;

public class Page {
	public static void pageDown(String index, int page) throws ParseException, IOException {
		CloseableHttpClient httpClient1 = HttpClients.createDefault();
		CloseableHttpResponse response1 = null;
		if (page == 1) {
			HttpGet request1 = new HttpGet("http://pic.netbian.com" + index);
			response1 = httpClient1.execute(request1);
		} else {
			HttpGet request1 = new HttpGet("http://pic.netbian.com" + index + "index_" + page + ".html");
			response1 = httpClient1.execute(request1);
		}
		HttpEntity httpEntity1 = response1.getEntity();
		String html1 = EntityUtils.toString(httpEntity1, "gb2312");
		org.jsoup.nodes.Document document1 = Jsoup.parse(html1);
		Elements utls = document1.select("div.wrap.clearfix ul.clearfix a");
		Elements title1 = document1.select("div.wrap.clearfix ul.clearfix img");
		PicDown picDown = new PicDown();
		try {
			for (int i = 0; i < 20; i++) {
				String name = title1.get(i).attr("alt");
				String utl = "http://pic.netbian.com" + utls.get(i).attr("href");
				picDown.Down(utl, name);
			}
			WelcomeInterface.log.append("\n\r\n\r***************** 第  " + page + "  页下载完成 *****************\n\r\n\r");
		} catch (Exception e) {
			WelcomeInterface.log.append("没有该图片！\n\r");
		}
	}
}
